package aos.ydksxt.service.xxdjgl;

import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.core.utils.AOSUtils;
import aos.framework.web.router.HttpModel;
import aos.ydksxt.dao.DjTdsyqdjxx;
import aos.ydksxt.service.common.CommonService;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 土地关系信息管理服务
 * Created by Stiofan on 2017/1/19.
 */
@Service
public class TdczxxglService extends CommonService {

    @Override
    @Transactional
    public void initView(HttpModel httpModel) {
        httpModel.setViewPath("/ydksxt/xxdjgl/tdczxxgl.jsp");
    }
    @Transactional
    public void queryTdczxxByTdbh(HttpModel httpModel) {
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto("tdbh", inDto.get("tdbh"));
        List tdcxxxs = persistenceDAO.findAllBySql("select nvl(kz.shxydm, xx.nsrsbh) nsrsbh,\n" +
                "       xx.nsrmc,\n" +
                "       syq.*,\n" +
                "       syq.tdsyq_ysmj * syq.tdsyq_ysje * 12 tdsyq_zlje\n" +
                "  from ydks.dj_tdsyqdjxx syq, ydks.dj_ryxx xx, ydks.dj_ryxx_kz kz\n" +
                " where syq.djxh = xx.djxh\n" +
                "   and xx.djxh = kz.djxh\n" +
                "   and syq.yxbz = 'Y'\n" +
                "   and syq.tdsyqlx_dm = '03'\n" +
                "   and xx.yxbz = 'Y'\n" +
                "   and kz.yxbz = 'Y'\n" +
                "   and syq.tdbh = :tdbh", params);
        httpModel.setOutMsg(AOSJson.toJson(AOSUtils.object2Map(tdcxxxs)));
    }
    @Transactional
    public void zfTdsysdjxxByTdsyquuid(HttpModel httpModel) {
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto("tdsyquuid", inDto.get("tdsyquuid"));
        DjTdsyqdjxx djTdsyqdjxx = (DjTdsyqdjxx) persistenceDAO.findSingleByHql("from DjTdsyqdjxx xx where xx.tdsyquuid=:tdsyquuid", params);
        djTdsyqdjxx.setZfrq(getDateTime());
        djTdsyqdjxx.setZfrDm(getCzryDm(httpModel));
        djTdsyqdjxx.setZfyy(inDto.getString("zfyy"));
        djTdsyqdjxx.setYxbz("N");
        djTdsyqdjxx.setXgrDm(getCzryDm(httpModel));
        djTdsyqdjxx.setXgrq(getDateTime());
        Dto outDto = Dtos.newOutDto();
        try {
            persistenceDAO.saveOrUpdate(djTdsyqdjxx);
            outDto.setAppCode("suc");
        } catch (Exception e) {
            outDto.setAppCode("err");
            outDto.setAppMsg(e.getMessage());
        }
        httpModel.setOutMsg(AOSJson.toJson(outDto));
    }
}
